﻿var countdown = {};

countdown.maxValue = 0;
countdown.currentValue = 0;
countdown.initialCallback = null;
countdown.intervalCallback = null;
countdown.finishCallback = null;

countdown.initial = function (value) {
    countdown.maxValue = value;
    countdown.currentValue = countdown.maxValue;
    if (countdown.initialCallback) {
        countdown.initialCallback();
    }
}

countdown.run = function () {
    interval = setInterval(function () {
        if (countdown.currentValue == 0) {
            clearInterval(interval);
            if (countdown.finishCallback) {
                countdown.finishCallback();
            }
            return;
        } else {
            countdown.currentValue--;
            if (countdown.intervalCallback) {
                countdown.intervalCallback();
            }
        }
    }, 1000);
}